package com.qianf.qfoffice.service.impl;

import com.qianf.qfoffice.dao.StudentDao;
import com.qianf.qfoffice.entity.Grade;
import com.qianf.qfoffice.entity.Grades;
import com.qianf.qfoffice.entity.Student;
import com.qianf.qfoffice.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class StudentServiceImpl implements StudentService {



    @Autowired
    private StudentDao studentDao;

    @Override
    public Student findStudentByUno(String uno) {
        return studentDao.findStudentByUno(uno);
    }

    @Override
    public int addStudent(Student student) {
        return studentDao.addStudent(student);
    }

    @Override
    public List<Grade> findAllGrade() {
        return studentDao.findAllGrade();
    }

    @Override
    public Grades getGradesNum() {
        List<Map> mapList = studentDao.getGradesNum();

        List<String> grades = new ArrayList<>();
        List<Integer> counts = new ArrayList<>();

        for (Map map : mapList) {

            String name = (String) map.get("name");
            Long num = (Long) map.get("num");

            counts.add(num.intValue());
            grades.add(name);

        }


        Grades grades1 = new Grades();
        grades1.setGrades(grades);
        grades1.setCounts(counts);

        return grades1;
    }
}
